﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common.JWT
{
    public interface IJsonToken
    {
        /// <summary>
        /// 数据编码
        /// </summary>
        /// <typeparam name="T">数据类型</typeparam>
        /// <param name="payload">数据</param>
        /// <param name="key">加密Key</param>
        /// <param name="algorithm">加密算法类型</param>
        /// <returns></returns>
        string Encode<T>(T payload, string key, JwtHashAlgorithm algorithm = JwtHashAlgorithm.HS256);
        /// <summary>
        /// 数据编码
        /// </summary>
        /// <typeparam name="T">数据类型</typeparam>
        /// <param name="extraHeaders">头部</param>
        /// <param name="payload">数据</param>
        /// <param name="key">加密Key</param>
        /// <param name="algorithm">加密算法类型</param>
        string Encode<T>(IDictionary<string, string> extraHeaders, T payload, string key, JwtHashAlgorithm algorithm = JwtHashAlgorithm.HS256);
        /// <summary>
        /// 数据解码
        /// </summary>
        /// <typeparam name="T">数据类型</typeparam>
        /// <param name="token">jwt-token</param>
        /// <param name="key">加密Key</param>
        /// <returns></returns>
        T Decode<T>(string token, string key);
        /// <summary>
        /// 验证
        /// </summary>
        /// <param name="payload">数据</param>
        /// <param name="payloadJson">数据json格式</param>
        /// <param name="header">Base64-safeurl编码的头部信息</param>
        /// <param name="decodedCrypto">Base64编码的签名</param>
        /// <param name="key">加密key</param>
        bool Verify(string payload, string payloadJson, string header, string decodedCrypto, string key);
        /// <summary>
        /// 验证数据是否过期
        /// </summary>
        /// <param name="header"></param>
        /// <returns></returns>
        bool IsDataExp(string header);
    }
}
